﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft Corp." file="RestOperation.cs">
//   All rights reserved. See License.txt in the project root for license information.
// </copyright>
// 
// --------------------------------------------------------------------------------------------------------------------
namespace RestClient
{
    using System.Net;
    using System.Threading.Tasks;

    public abstract class RestOperation : IRestOperation
    {
        protected readonly IRestServiceContext ServiceContext;

        protected RestOperation(IRestServiceContext serviceContext)
        {
            this.ServiceContext = serviceContext;
        }

        public Task<WebResponse> Execute()
        {
            var request = this.ServiceContext.BuildRequest(this.GetRequestContext);
            return request.GetResponseAsync();
        }

        protected abstract RequestContext GetRequestContext();
    }
}